var number = '';
var user_id='';

$(function () {
	// 旅客数量
	number = getUrlParam("number");
	if(number==1){
		console.log("number-->"+number);
		document.getElementById("traveller_Msg2").style.display="none";//隐藏
	}
	// 酒店的id
	var hotel_id = getUrlParam("hotel_id");
	console.log("酒店的id-->"+hotel_id);
	// 定义去用户id
	
	alert(user_id);
	console.log("用户的id---->"+user_id);
	
	var startDate = getUrlParam("startDate");
	var endDate = getUrlParam("endDate");
	var sumPrice = getUrlParam("sumPrice");
	console.log("酒店的sumPrice-->"+sumPrice);
	getHotel(hotel_id);
	$("#sum_Price").html(sumPrice);
	$("#sum_Price_end").html(sumPrice);
	// 入住天数
	var days = DateDiff(startDate,endDate);
	console.log("相差天数-->"+days);
	$("#add_days").html(days);
	// 获取当前日期
	var date_add = getNowFormatDate();
	$("#getdate").html(date_add);
	// 获取当前星期几
	var getWeekDates = getWeekDate();
	console.log("今天星期-->"+getWeekDates);
	$("#getWeekDate").html(getWeekDates);
	// 获取酒店type
	searchHotelType_id(hotel_id);
});

// 根据hotel_id得到hotel对象
function getHotel(hotel_id) {
	console.log("hotel_id----->"+hotel_id)
	$.get(
			"/JavaWeb项目_第六组/hotel",
			{method:"findHotelByHotelId",hotel_id:hotel_id},
			function (data) {
				console.log("hotel_text--->"+data.hotel_text);
				var hotel_text = data.hotel_text;
				var hotel_price = data.hotel_price;
				// 全局变量设置
				
				$("#hotel_text").html(hotel_text);
				$("#hotel_price").html(hotel_price);
			});
}

/*两个日期相差天数的比较*/
function DateDiff(sDate1, sDate2) {  //sDate1和sDate2是yyyy-MM-dd格式
 
    var aDate, oDate1, oDate2, iDays;
    aDate = sDate1.split("-");
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为yyyy-MM-dd格式
    aDate = sDate2.split("-");
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
    return iDays;  //返回相差天数
}

//获取url中的参数
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg); //匹配目标参数
	if (r != null) return decodeURI(r[2]);
	return null; //返回参数值
}

// 获取当前日期2020-07-11
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

/**
 *获取当前星期几
 *
*/
function getWeekDate() {
   var now = new Date();
   var day = now.getDay();
   var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
   var week = weeks[day];
   return week;
}

/**
 * 产品类型
 * 查询hotel_type
 */
function searchHotelType_id (hotel_id) {
	console.log("hotel_id--->"+hotel_id);
	$.get(
		"/JavaWeb项目_第六组/hotel",
		{method:"findTypeByHotelId",hotel_id:hotel_id},
		function (data) {
			if (data==null||data=='') {
				$("#hotel_type").html('基础房');
				$("#see_number").html(0);
				return;
			}
			console.log("data----->"+data.type);
			var type = data.type;
			var see_number = data.see_number;
			$("#getHotelType").html(type);
		}
	);
}
